/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.click.app.model;

/**
 *
 * @author arnold
 */
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

@Entity
@Table(name = "request_clients")
public class RequestClient extends BaseObject implements Serializable {

    private static final long serialVersionUID = 3832626162173359411L;
    private Long id;
    private Date dateRequestClient;
    private Cart cart;
    private List<Product> products;
    private Float quantity;
    private Float price;
    private Float totalPrice;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "date_request_client")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getDateRequestClient() {
        return dateRequestClient;
    }

    public void setDateRequestClient(Date dateRequestClient) {
        this.dateRequestClient = dateRequestClient;
    }

    @Override
    public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append("id", this.id);
        return sb.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final RequestClient other = (RequestClient) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 67 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    /**
     * @return the cart
     */
    @ManyToOne(optional = false)
    public Cart getCart() {
        return cart;
    }

    /**
     * @param cart the cart to set
     */
    public void setCart(Cart cart) {
        this.cart = cart;
    }

    /**
     * @return the product
     */
    @OneToMany
    @JoinTable(name = "request_clients_products",
    joinColumns = {
        @JoinColumn(name = "request_clients_id", unique = true)
    },
    inverseJoinColumns = {
        @JoinColumn(name = "products_id")
    })
    public List<Product> getProducts() {
        if (products == null) {
            products = new ArrayList<Product>();
        }
        return products;
    }

    /**
     * @param product the product to set
     */
    public void setProducts(List<Product> products) {
        this.products = products;
    }

    /**
     * @return the quantity
     */
    public Float getQuantity() {
        return quantity;
    }

    /**
     * @param quantity the quantity to set
     */
    public void setQuantity(Float quantity) {
        this.quantity = quantity;
    }

    /**
     * @return the price
     */
    public Float getPrice() {
        return price;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(Float price) {
        this.price = price;
    }

    /**
     * @return the totalPrice
     */
    @Column(name = "total_price")
    public Float getTotalPrice() {
        return totalPrice;
    }

    /**
     * @param totalPrice the totalPrice to set
     */
    public void setTotalPrice(Float totalPrice) {
        this.totalPrice = totalPrice;
    }

    @Transient
    public Product getProduct() {
        return products.get(0);
    }
}
